package com.yunbao.hujin.myzoomcenter;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.yunbao.hujin.myzoomcenter.banner.ConvenientBanner;
import com.yunbao.hujin.myzoomcenter.banner.holder.CBViewHolderCreator;
import com.yunbao.hujin.myzoomcenter.banner.holder.NetworkImageHolderView;
import com.yunbao.hujin.myzoomcenter.banner.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 轮播图
 */
public class BannerActivity extends AppCompatActivity implements OnItemClickListener {

    ConvenientBanner banner;        //轮播图

    private int[] page_indicatorId; //指示器
    private List<String> mBannerList = new ArrayList<>(); //banner图片

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bank);

        banner = findViewById(R.id.banner);
        setBanner();
    }

    /**
     * 处理轮播图
     */
    private void setBanner() {
        mBannerList.add("http://www.apkbus.com/data/attachment/forum/201710/23/122713c5p5msalrxazdnbb.jpg");
        mBannerList.add("http://p0.ifengimg.com/pmop/2017/1022/76A0A483055FBA896F2DD37605FF68B5A74B7346_size240_w950_h543.jpeg");
//        mBannerList.add("http://www.apkbus.com/data/attachment/forum/201708/24/154313el6i0y06yqhyqh63.png");
        mBannerList.add("http://www.apkforum/201708/24/154313el6i0y06yqhyqh63.png");//错误图片地址

        page_indicatorId = new int[]{R.mipmap.ic_page_indicator, R.mipmap.ic_page_indicator_focused};
//        page_indicatorId = new int[]{R.mipmap.line, R.mipmap.line_sel};
        //设置指示器
        banner.setPageIndicator(page_indicatorId);
        //    处理轮播图
        banner.setPages(new CBViewHolderCreator<NetworkImageHolderView>() {

            @Override
            public NetworkImageHolderView createHolder() {
                return new NetworkImageHolderView();
            }
        }, mBannerList);

        banner.setOnItemClickListener(this);
        banner.startTurning(3000);
    }

    @Override
    public void onItemClick(int position) {
        Toast.makeText(this, mBannerList.get(position).substring(0, 20), Toast.LENGTH_SHORT).show();
    }


    public void bannerStart(boolean flag) {
        if (flag) {
            banner.startTurning(3000);
        } else {
            if (null != banner) {
                banner.stopTurning();
            }
        }
    }

}
